<template>
  <div class="filterBoxCollectionWarp"
       @mouseenter="()=>{visiable=true}"
       @mouseleave="()=>{visiable=false}">
    <div
      class="filterBoxCollectionWarpTitle"
      @click="()=>{visiable=true}"
    >
      <p class="tipStyle" v-if="checkNull(queryParam)">{{ placeholder || $t('advancedSearch') }}</p>
      <span
        v-for="(value,key) in queryParam"
        :key="key"
      >
        <a-tag
          closable
          @close="tagCose(arguments,key)"
          v-if="!excludeOptions.includes(key)&&value"
        >
          {{ $t(value) }}
        </a-tag>
      </span>
    </div>
    <div
      v-show="visiable"
      class="filterBoxCollectionWarpContent"
    >
      <div class="filterBoxCollectionInner">
        <slot></slot>
        <div class="filterBoxCollectionWarpContentButton">
          <!-- <a-button @click="clickCancel">{{ $t('cancel') }}</a-button> -->
          <a-button type="primary" @click="clickSearch">{{ $t('inquiry') }}</a-button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    queryParam: {
      type: Object,
      required: true
    },
    placeholder: {
      type: String,
      required: false
    },
    excludeOptions: {
      type: Array,
      default: () => {
        return []
      }
    },
    filterBoxCls: {
      type: String,
      default: 'filterBoxCollectionWarp'
    }
  },
  data () {
    return {
      visiable: false
    }
  },
  mounted () {
    //document.body.addEventListener('click', this.clickOuterHideBox, false)
  },
  methods: {
    checkNull (queryParam) {
      let tag = true
      // eslint-disable-next-line no-restricted-syntax
      for (const key in queryParam) {
        if (queryParam[key]) {
          tag = false
        }
      }
      console.log(tag)
      return tag
    },
    tagCose (e, key) {
      this.queryParam[key] = ''
      this.$emit('removetag', key)
    },
    handleLeave () {
      this.visiable = false
    },
    changeVisible (val) {
      this.visiable = val
    },
    clickSearch () {
      this.$emit('search')
      this.visiable = false
    },
    clickCancel () {
      this.$emit('cancel')
      this.visiable = false
    },
    clickOuterHideBox (e) {
      const cls = '.' + this.filterBoxCls
      let querySelector = document.querySelector(cls);
      if (!querySelector || querySelector.contains(e.target)) {
        return
      }
      if (this.visiable) {
        this.visiable = false
      }
    }
  },
  beforeDestroy () {
    document.body.removeEventListener('click', this.clickOuterHideBox)
  }
}
</script>
<style lang="less" scoped>
.filterBoxCollectionWarp {
  position: relative;
  .filterBoxCollectionWarpTitle {
    border: 1px solid #d9d9d9;
    width: 100%;
    border-radius: @border-radius-base;
    display: flex;
    align-items: center;
    padding:0 5px 5px 5px;
    flex-wrap: wrap;
    max-height: 32px;
    min-height: 32px;
    overflow: auto;
    >span {
      margin-top:5px;
    }
    .tipStyle{
     width: 94%;
     color:#ddd;
     position: absolute;
     top: 6px;
     overflow: hidden;
     text-overflow: ellipsis;
     white-space: nowrap;
    }
  }
  .filterBoxCollectionWarpContent {
    position: absolute;
    top: 32px;
    z-index:60;
    background: #fff;
    padding-top: 8px;
    min-width: 100%;
    & > div.filterBoxCollectionInner{
      border: 1px solid #d9d9d9;
      border-radius: @border-radius-base;
      min-width: 100%;
      padding: 16px;
    }
  }
  .filterBoxCollectionWarpContentButton {
    text-align: right;
    margin-top:5px;
  }
}
</style>
<style lang="less">
.filterBoxCollectionWarpContentButton {
  .ant-btn {
    min-width:0;
    padding:1px 15px;
    height: auto !important;
    margin-left: 10px;
  }

}
.filterBoxCollectionWarp {
  .ant-form-item-label {
    font-weight: bold;
    line-height: 1em;
    label {
      font-size: 0.9em;
    }
  }
  .ant-form-item {
    margin-bottom: 12px;
  }
}
</style>
